
add_custom_target(lib)

set(LIB_SHARED_TARGET ${LIB_TARGET_NAME})
set(LIB_STATIC_TARGET ${LIB_TARGET_NAME}_static)

if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()

set(LIB_TARGET_SOURCES)

set(LIB_PUBLIC_HEADERS
    ${PROJECT_SOURCE_DIR}/include/common/point_type.h
    ${PROJECT_SOURCE_DIR}/include/common/map_info.h
    ${PROJECT_SOURCE_DIR}/include/common/map_utility.h
    ${PROJECT_SOURCE_DIR}/include/filter/map_filter.h
    ${PROJECT_SOURCE_DIR}/include/map_decoder/map_decoder.h
    ${PROJECT_SOURCE_DIR}/include/track/tracker.h
    ${PROJECT_SOURCE_DIR}/include/common/map_road_marking_defs.h
)

#################################### BUILD LIB ##################################
add_subdirectory(common)
add_subdirectory(filter)
add_subdirectory(map_decoder)
add_subdirectory(evaluate)
if(NOT BUILD_EVAL_LIB)
    add_subdirectory(vis)
    add_subdirectory(fit)
    add_subdirectory(track)  
endif()


# list(APPEND LIB_TARGET_SOURCES 
#     DataManager.cpp)

######################## SHARED LIBRARY #######################

add_library(${LIB_SHARED_TARGET} SHARED
    ${LIB_TARGET_SOURCES})

if(NOT DEFINED AMBA_SDK_DIR)
    target_link_libraries(
        ${LIB_SHARED_TARGET}
        ${Boost_LIBRARIES}
        boost_json
    )
else()
    target_link_libraries(
        ${LIB_SHARED_TARGET}
        ${AMBA_SDK_OSS_LIBS}
    )
endif()

set_target_properties(${LIB_SHARED_TARGET} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
)

set_target_properties(${LIB_SHARED_TARGET} PROPERTIES PUBLIC_HEADER "${LIB_PUBLIC_HEADERS}")
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

######################## SHARED LIBRARY #######################

add_library(${LIB_STATIC_TARGET} STATIC
    ${LIB_TARGET_SOURCES})

set_target_properties(${LIB_STATIC_TARGET} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
)

set_target_properties(${LIB_STATIC_TARGET} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL -Wl")
set_target_properties(${LIB_STATIC_TARGET} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
set_target_properties(${LIB_STATIC_TARGET} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

##########################################

add_dependencies(lib ${LIB_SHARED_TARGET} ${LIB_STATIC_TARGET})

##########################################

INSTALL(TARGETS ${LIB_SHARED_TARGET} ${LIB_STATIC_TARGET}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
        PUBLIC_HEADER DESTINATION "include"
)

###############################################################################

#################################### BUILD EXEC ###############################

if(NOT DEFINED AMBA_SDK_DIR AND NOT BUILD_EVAL_LIB)
    add_executable(${TEST_TARGET_NAME} 
        main.cpp
        perception_visualizer.cpp
        perception_visualizer_debug.cpp
        )

    set_target_properties(${TEST_TARGET_NAME} PROPERTIES
        CXX_STANDARD "17"
        CXX_STANDARD_REQUIRED "YES"
        CXX_EXTENSIONS "NO"
        ARCHIVE_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
        LIBRARY_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
        RUNTIME_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
        )
    set_target_properties(${TEST_TARGET_NAME} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
    set_target_properties(${TEST_TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION})

    target_link_libraries(
    ${TEST_TARGET_NAME}
    ${LIB_TARGET_NAME}
    boost_thread boost_json
    pthread
    ${CMAKE_THREAD_LIBS_INIT} 
    ${Boost_LIBRARIES}
    ${PCL_LIBRARIES}
    ${OpenCV_LIBS}  
    )
endif()








